<?php

class VideosController extends Controller
{
	
	public function actionIndex()
	{
		$data = array();
		
		$oVideos = new Videos();
		
		$oRowset = $oVideos->userId(Yii::app()->user->id)->findAll();
		
		$this->render('index', array(
			'oVideos' => $oRowset
		));
	}
	
	public function actionAdd()
	{
		$oRequest = new CHttpRequest();
		
		$data = array();
		
		$oVideos = new Videos();
		
		$id = $oRequest->getParam('id');
		
		$oRow = $oVideos->userId(Yii::app()->user->id)->findByPk($id);
		
		if(!$oRow)
			$oRow = $oVideos;
		
		if($oRequest->getIsPostRequest())
		{
			$data = $_POST;
			
			$oRow->setAttributes($_POST, false);
			
			$oRow->user_id = Yii::app()->user->id;
			$oRow->lang = Yii::app()->language;

			if($oRow->validate() && $oRow->save())
			{
				$id = $oRow->getPrimaryKey();
			}
		}
		
		
		$this->render('add', array(
			'oRow' => $oRow
		));
	}
}